import tkinter as tk

# <Button-1>  鼠标左键
# <Button-2>   鼠标中间键（滚轮）
# <Button-3>  鼠标右键
# <Double-Button-1>   双击鼠标左键
# <Double-Button-3>   双击鼠标右键
# <Triple-Button-1>   三击鼠标左键
# <Triple-Button-3>   三击鼠标右键

chess = [[0 for i in range(19)] for j in range(19)]
print(chess)

root = tk.Tk()
root.geometry('450x430')

img1 = tk.PhotoImage(file = '美女.png')
chessLabel = tk.Label(root,image=img1)
chessLabel.place(x=1,y=0)

isBlack = True
def foo1(event):
    global isBlack

    print(f'{event.x},{event.y}')
    x = int((event.x - 42 + 10.5) // 20.1)
    y = int((event.y - 25 + 10.2) // 20.4)
    print(x, y)
    if x >= 0 and x < 19 and y >= 0 and y < 19:
        tmpX = 42 + 20.1 * x - 10.05
        tmpY = 25 + 20.4 * y - 10.2
        if isBlack:
            chess[y][x] = 1
            tmpImgLabel = tk.Label(root, image=blackImg)
            tmpImgLabel.place(x=tmpX, y=tmpY)
        else:
            chess[y][x] = 2
            tmpImgLabel = tk.Label(root, image=whiteImg)
            tmpImgLabel.place(x=tmpX, y=tmpY)
        isBlack = not isBlack
    print(chess)


chessLabel.focus_set()
chessLabel.bind('<Button-1>',foo1)

blackImg = tk.PhotoImage(file="black.png")
whiteImg = tk.PhotoImage(file="white.png")
black1 = tk.Label(root,image=blackImg)
black1.place(x=100,y=100)

root.mainloop()
